package com.authorization.project.authorization.service.impl;

import java.util.List;

import com.authorization.project.authorization.domain.AuthorizationMoudleMapping;
import com.authorization.project.authorization.service.IAuthorizationMoudleMappingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.authorization.project.authorization.mapper.AuthorizationMoudleMappingHistoryMapper;
import com.authorization.project.authorization.domain.AuthorizationMoudleMappingHistory;
import com.authorization.project.authorization.service.IAuthorizationMoudleMappingHistoryService;

/**
 * 授权信息-模块中间表-历史表Service业务层处理
 * 
 * @author 李晓雷
 * @date 2020-04-29
 */
@Service
public class AuthorizationMoudleMappingHistoryServiceImpl implements IAuthorizationMoudleMappingHistoryService 
{
    @Autowired
    private AuthorizationMoudleMappingHistoryMapper authorizationMoudleMappingHistoryMapper;

    @Autowired
    private IAuthorizationMoudleMappingService iAuthorizationMoudleMappingService;

    /**
     * 查询授权信息-模块中间表-历史表
     * 
     * @param id 授权信息-模块中间表-历史表ID
     * @return 授权信息-模块中间表-历史表
     */
    @Override
    public AuthorizationMoudleMappingHistory selectAuthorizationMoudleMappingHistoryById(Long id)
    {
        return authorizationMoudleMappingHistoryMapper.selectAuthorizationMoudleMappingHistoryById(id);
    }

    /**
     * 查询授权信息-模块中间表-历史表列表
     * 
     * @param authorizationMoudleMappingHistory 授权信息-模块中间表-历史表
     * @return 授权信息-模块中间表-历史表
     */
    @Override
    public List<AuthorizationMoudleMappingHistory> selectAuthorizationMoudleMappingHistoryList(AuthorizationMoudleMappingHistory authorizationMoudleMappingHistory)
    {
        return authorizationMoudleMappingHistoryMapper.selectAuthorizationMoudleMappingHistoryList(authorizationMoudleMappingHistory);
    }

    /**
     * 新增授权信息-模块中间表-历史表
     * 
     * @param authorizationMoudleMappingHistory 授权信息-模块中间表-历史表
     * @return 结果
     */
    @Override
    public int insertAuthorizationMoudleMappingHistory(AuthorizationMoudleMappingHistory authorizationMoudleMappingHistory)
    {
        return authorizationMoudleMappingHistoryMapper.insertAuthorizationMoudleMappingHistory(authorizationMoudleMappingHistory);
    }

    /**
     * 修改授权信息-模块中间表-历史表
     * 
     * @param authorizationMoudleMappingHistory 授权信息-模块中间表-历史表
     * @return 结果
     */
    @Override
    public int updateAuthorizationMoudleMappingHistory(AuthorizationMoudleMappingHistory authorizationMoudleMappingHistory)
    {
        return authorizationMoudleMappingHistoryMapper.updateAuthorizationMoudleMappingHistory(authorizationMoudleMappingHistory);
    }

    /**
     * 批量删除授权信息-模块中间表-历史表
     * 
     * @param ids 需要删除的授权信息-模块中间表-历史表ID
     * @return 结果
     */
    @Override
    public int deleteAuthorizationMoudleMappingHistoryByIds(Long[] ids)
    {
        return authorizationMoudleMappingHistoryMapper.deleteAuthorizationMoudleMappingHistoryByIds(ids);
    }

    /**
     * 删除授权信息-模块中间表-历史表信息
     * 
     * @param id 授权信息-模块中间表-历史表ID
     * @return 结果
     */
    @Override
    public int deleteAuthorizationMoudleMappingHistoryById(Long id)
    {
        return authorizationMoudleMappingHistoryMapper.deleteAuthorizationMoudleMappingHistoryById(id);
    }

    /**
     * 根据客户编号和历史主键存关系表
     * @param userid
     */
    @Override
    public void insertAuthorizationMoudleMappingHistoryByUserid(String userid, Long authorizationHistoryId) {
        AuthorizationMoudleMapping authorizationMoudleMapping = new AuthorizationMoudleMapping();
        authorizationMoudleMapping.setUserid(userid);
        List<AuthorizationMoudleMapping> authorizationMoudleMappingList = iAuthorizationMoudleMappingService.selectAuthorizationMoudleMappingList(authorizationMoudleMapping);
        authorizationMoudleMappingList.stream().forEach(authorizationMoudleMapping1 -> {
            AuthorizationMoudleMappingHistory authorizationMoudleMappingHistory = new AuthorizationMoudleMappingHistory();
            authorizationMoudleMappingHistory.setModuleId(authorizationMoudleMapping1.getModuleId());
            authorizationMoudleMappingHistory.setPackageId(authorizationMoudleMapping1.getPackageId());
            authorizationMoudleMappingHistory.setUserid(userid);
            authorizationMoudleMappingHistory.setAuthHistoryId(authorizationHistoryId);
            this.insertAuthorizationMoudleMappingHistory(authorizationMoudleMappingHistory);
        });
    }

    /**
     *
     * @param userid
     * @param productId
     * @return
     */
    @Override
    public List<Long> selectMoudleIdsByUserId(String userid, Long productId) {
        return authorizationMoudleMappingHistoryMapper.selectMoudleIdsByUserId(userid, productId);
    }

    /**
     * 根据历史ID查询选中模块
     * @param historyId
     * @return
     */
    @Override
    public List<Long> selectMoudleIdsById(String historyId) {
        return authorizationMoudleMappingHistoryMapper.selectMoudleIdsById(historyId);
    }
}
